<?php

namespace App\Http\Controllers\API;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Illuminate\Pagination\Paginator;
use App\Article;
use DB;

class ArticleController extends Controller
{
     
    // 采集
    public function curl(Request $request){
        // 采集的地址
        $url = 'https://lapi.jd.com/news/list?source=pc-news-channel&action=1&page=1&type=2&innerLink=undefined&pin=&uuid=&jda=&callback=articlelist&_=1572333219845';
        // 获取整个URL页面
        $res = file_get_contents($url);
        print_r($res);

        // $data = DB::table('article')->insert($res);
        // if($data){
        //     echo "添加成功";
        // }
    }

    // 列表的展示加分页
    public function list(){
        // 从数据库查询数据并返回分页类型
        $data = DB::table('article')->paginate(2);
        // 把分页数据返回到视图
        return view('article.list',['data'=>$data]);
    }
















    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        //
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
        //
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        //
    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function show($id)
    {
        //
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function edit($id)
    {
        //
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, $id)
    {
        //
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
        //
    }
}
